import { Component } from "react";
import Script from "react-load-script";
import "./index.css";

export default class Gopher2d extends Component {
	constructor(props) {
		super(props);
		this.state = {
			isShow: this.props.isShow,
		};
		if (this.state.isShow) {
			// console.log("gopher: 已开启");
		}
	}
	handleScriptError() {
		console.log("gopher加载失败");
	}
	render() {
		if (this.state.isShow) {
			return (
				<div className="gopher">
					<canvas
						style={{
							zIndex: 1,
							textAlign: "center",
						}}
						className="gopher"
						id="view"
					></canvas>
					<Script
						url="/js/gopher2d.js"
						onError={this.handleScriptError.bind(this)}
					></Script>
				</div>
			);
		} else {
			return <div></div>;
		}
	}
}
